﻿using System;
using System.Collections.Generic;

namespace SimpleHTMLRender
{
    /// <summary>
    /// Make it possible to use the htmlnode in a LINQ expression.
    /// </summary>
    /// <typeparam name="IteratorType"></typeparam>
    /// <typeparam name="ContainerType"></typeparam>
    public class EnumerableWrapper<IteratorType> : IEnumerable<IteratorType>
    {
        private System.Collections.IEnumerable _enumerable;

        public EnumerableWrapper(System.Collections.IEnumerable enumerable)
        {
            _enumerable = enumerable;
        }
        public IEnumerator<IteratorType> GetEnumerator()
        {
            if (_enumerable != null)
            {
                foreach (var item in _enumerable)
                {
                    IteratorType a = (IteratorType)item;
                    if (a != null)
                    {
                        yield return a;
                    }
                }
            }
        }

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            throw new NotImplementedException();
        }
    }
}
